package com.yang.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller

public class ModelTest1 {
//    @RequestMapping("/m1/t1")
//    public String test(HttpServletRequest request, HttpServletResponse response,Model model){
//        HttpSession session = request.getSession();
//        System.out.println(session.getId());
//        model.addAttribute("msg",session.getId());
//        return "test";
//    }
//====================== 无视图解析器 ===========================
    @RequestMapping("/m1/t1")
    //重定向
    public String test(Model model){
        model.addAttribute("msg","ModelTest1");
        return "redirect:/index.jsp";
    }
    @RequestMapping("/m1/t2")
    //转发
    public String test2(Model model){
        model.addAttribute("msg","ModelTest2");
        return "/index.jsp";
    }
    @RequestMapping("/m1/t3")
    //转发
    public String test3(Model model){
        model.addAttribute("msg","ModelTest3");
        return "forward:/index.jsp";
    }
    // ======================= 有视图解析器 =============================
    @RequestMapping("/rsm2/t1")
    public String test1(){
        //转发
        return "test";
    }

    @RequestMapping("/rsm2/t2")
    public String test2(){
        //重定向
        return "redirect:/index.jsp";
    }
}
